require 'nvim-treesitter.configs'.setup {
  -- If TS highlights are not enabled at all, or disabled via `disable` prop, highlighting will fallback to default Vim syntax highlighting
  highlight = {
    enable = true,
    -- 开启c的高亮 c 大的静态数组会很卡, 所以关闭
    disable = { 'org', 'vim', 'lua', 'c', 'cpp', 'help' }, -- help, vim, lua 高亮会冲突, 所以需要安装但是不使用
    additional_vim_regex_highlighting = { 'org' },
  },
  -- ensure_installed = "maintained", 这个可以安装目前维护的所有语言 treesitter 插件。
  -- ensure_installed = { 'org', 'lua', 'java', 'rust', 'c', 'nix', 'bash', 'go', 'scala', 'cpp' },
  ensure_installed = { 'org', 'lua', 'vim', 'help', 'java', 'rust', 'c', 'nix', 'bash', 'go', 'cpp', 'make', 'devicetree' },

    require'nvim-treesitter.configs'.setup {
      matchup = {
        enable = true,              -- mandatory, false will disable the whole extension
        -- disable = { "c", "ruby" },  -- optional, list of language that will be disabled
        -- [options]
      },
    }
}

-- 从 https://github.com/nvim-treesitter/nvim-treesitter-textobjects 拷贝过来的配置
require('nvim-treesitter.configs').setup {
  textsubjects = {
    enable = true,
    prev_selection = ',', -- (Optional) keymap to select the previous selection
    keymaps = {
      ['.'] = 'textsubjects-smart',
      [';'] = 'textsubjects-container-outer',
      ['i;'] = 'textsubjects-container-inner',
    },
  },
}

require 'nvim-treesitter.configs'.setup {
  textobjects = {
    select = {
      enable = true,

      -- Automatically jump forward to textobj, similar to targets.vim
      lookahead = true,

      keymaps = {
        -- You can use the capture groups defined in textobjects.scm
        ["af"] = "@function.outer",
        ["if"] = "@function.inner",
        ["ac"] = "@class.outer",
        -- you can optionally set descriptions to the mappings (used in the desc parameter of nvim_buf_set_keymap
        ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
      },
      -- You can choose the select mode (default is charwise 'v')
      selection_modes = {
        ['@parameter.outer'] = 'v', -- charwise
        ['@function.outer'] = 'V', -- linewise
        ['@class.outer'] = '<c-v>', -- blockwise
      },
      -- If you set this to `true` (default is `false`) then any textobject is
      -- extended to include preceding xor succeeding whitespace. Succeeding
      -- whitespace has priority in order to act similarly to eg the built-in
      -- `ap`.
      include_surrounding_whitespace = true,
    },
    move = {
      enable = true,
      set_jumps = true, -- whether to set jumps in the jumplist
      goto_next_start = {
        ["xl"] = "@function.outer",
        ["xL"] = "@class.outer",
      },
      goto_next_end = {
        ["xk"] = "@function.outer",
        ["xK"] = "@class.outer",
      },
      goto_previous_start = {
        ["xh"] = "@function.outer",
        ["xH"] = "@class.outer",
      },
      goto_previous_end = {
        ["xj"] = "@function.outer",
        ["xJ"] = "@class.outer",
      },
    },
  },
}

require('nvim-treesitter.install').compilers = { "clang", "gcc" }

